<!DOCTYPE html>
<html lang="en">
    <head>
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <meta content="Bmob,BmobCloud,bomb,BaaS,mBaaS,PaaS,Serverless,FaaS,Function as a Service,Backend as a Service,serverless computing,cloud function,后端云,bmob后端云,小程序云,小程序后端,云数据库,云存储,文件存储,云函数,云端代码,定时任务,游戏后端,游戏云,用户系统,无服务器函数,移动开发,app开发,小程序开发,云端一体化,互联网中间件" name="keywords"/>
            <meta content="国内首家专注于移动应用Serverless云服务的平台,Bmob后端云让移动开发更简单,全方位一体化的后端服务平台" name="description"/>
            
            
            
            <link rel="shortcut icon" href="../../img/favicon.ico">
        
        <script type="text/javascript" src="//game.bmob.cn/static/doc_union.js"></script>
            <!--
            <title>iOS - Bmob文档中心</title>
            -->
            <title>推送服务 &middot; iOS – Bmob后端云 </title>        
            
            <link href="../../css/bootstrap-custom.min.css" rel="stylesheet">
            <link href="../../css/font-awesome-4.5.0.css" rel="stylesheet">
            <link href="../../css/base.css" rel="stylesheet">
            <link rel="stylesheet" href="../../css/highlight.css">
            <link href="../../css/agate.css" rel="stylesheet">
            <link href="../../css/custom.css" rel="stylesheet" id="custom">
    </head>

    <body >

        <div class="navbar navbar-fixed-top" role="navigation">
    <div class="main-nav">
        <!-- Collapsed navigation -->
        <div class="navbar-header">
            <a class="navbar-brand" href="../..">
                <!--Bmob文档中心-->
                <img src="../../img/logo.png" alt="">
            </a>
        </div>

        <!-- Expanded navigation -->
        <div class="navbar-collapse collapse">

          <ul class="nav navbar-nav">
            
              <li class="pull-left">
                
					<a href="../..">文档首页</a>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="">数据服务</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">数据服务 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
								<li >
									<a href="../../data/android/">Android</a>
                                </li>
                            
                            
								<li >
									<a href="../../data/ios/">iOS</a>
                                </li>
                            
                            
								<li >
									<a href="../../data/csharp/">C#</a>
                                </li>
                            
                            
								<li >
									<a href="../../data/php/">PHP</a>
                                </li>
                            
                            
								<li >
									<a href="../../data/go/">GO</a>
                                </li>
                            
                            
								<li >
									<a href="../../data/restful/">REST API</a>
                                </li>
                            
                            
								<li >
									<a href="../../data/wechat_app_new/rm/">JavaScript</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../data/cocos2d_x/">Cocos2D-X</a>
                                </li>
							
                            
								<li >
									<a href="../../data/wechat_app/">小程序</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../data/wechat_app_new/">快应用</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../data/wechat_app_new/">Nodejs</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../data/wechat_app_new/">Cocos Creator</a>
                                </li>
							
                            
								<li >
									<a href="../../data/wechat_app_new/rm/">小程序(新)</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../data/kotlin/">Kotlin</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../data/python/">Python</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="../../cloud_function/android/">云函数</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">云函数 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../../cloud_function/android/">Android</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../cloud_function/ios/">iOS</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../cloud_function/java/">Java</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../cloud_function/python/">Python</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../cloud_function/csharp/">C#</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../cloud_function/php/">PHP</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../cloud_function/javascript/">JavaScript</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../cloud_function/restful/">REST API</a>
                                </li>
							
                            
								<li >
									<a href="../../cloud_function/web/">Web</a>
                                </li>
                            
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="../../sms/android/">短信服务</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">短信服务 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../../sms/android/">Android</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../sms/ios/">iOS</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../sms/php/">PHP</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../sms/javascript/">JavaScript</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../sms/restful/">REST API</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="">游戏实时后端</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">游戏实时后端 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
								<li >
									<a href="../../game/unity/quick_start/">Unity</a>
                                </li>
                            
                            
								<li >
									<a href="../../game/cocos_creator/quick_start/">Cocos Creator</a>
                                </li>
                            
                            
								<li >
									<a href="../../game/wechat_games/quick_start/">微信小游戏</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../game/cloud_function/develop_doc/">云函数</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../game/classic_case/">经典案例</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="">即时通讯</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">即时通讯 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
								<li >
									<a href="../../im/android/">Android</a>
                                </li>
                            
                            
								<li >
									<a href="../../im/ios/">iOS</a>
                                </li>
                            
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left active">
                
					<!--<a href="../android/">推送服务</a>-->
					<li class="dropdown active">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">推送服务 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../android/">Android</a>
                                </li>
							
                            
                                <li class="active">
                                    <a href="./">iOS</a>
                                </li>
							
                            
                                <li >
                                    <a href="../php/">PHP</a>
                                </li>
							
                            
                                <li >
                                    <a href="../javascript/">JavaScript</a>
                                </li>
							
                            
                                <li >
                                    <a href="../restful/">REST API</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="../../other/common_problem/">其他</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">其他 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../../other/common_problem/">常见问题</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../other/error_code/">错误码</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../other/data_safety/">数据安全</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../other/bql/">BQL</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li>
                  <a href="https://www.bmob.cn/repository/index" target="_blank">知识库</a>
              </li>
              <li>
                  <a href="http://doc.bmob.cn/video/index.html" target="_blank">视频教程</a>
              </li>
            </ul>
            
        </div>
    </div>
</div>

        <div class="pagebody" id="main-wrapper">
            <div class="sidebar">
                <div class="bs-sidebar hidden-print affix well" role="complementary">

	
		
	
		
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
		
	
		
				
				
				
				
				
				
				
				
				
		
	
		
				
				
				
				
				
		
	
		
				
				
				
				
				
		
	
		
				
				
		
	
		
				
				
					<div class="code-title">iOS</div>
				
				
				
				
		
	
		
				
				
				
				
		
	


	<ul class="nav bs-sidenav">
		
			
		
			
		
			
		
			
		
			
		
			
		
			
				
					
						
					
						
							
								
									
										<li class="active "><a href="#_1">推送证书设置指南</a>
											
											<ul class="nav nav-l2">
												<li><a class="itm-l2" href="#_2">创建应用</a></li>
											</ul>
											
											<ul class="nav nav-l2">
												<li><a class="itm-l2" href="#_3">创建和上传证书</a></li>
											</ul>
											
										</li>
									
										<li class=""><a href="#_4">推送使用</a>
											
											<ul class="nav nav-l2">
												<li><a class="itm-l2" href="#_5">推送消息接收</a></li>
											</ul>
											
											<ul class="nav nav-l2">
												<li><a class="itm-l2" href="#_6">推送消息发送</a></li>
											</ul>
											
										</li>
									
								
							
						
					
						
					
						
					
						
					
				
			
		
			
		
	</ul>
</div>
            </div>
            <div class="content" role="main">
                <div class="wrap">
                    

<h2 id="_1">推送证书设置指南<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h2>
<h3 id="_2">创建应用<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h3>
<p>1.进入并登录<a href="https://developer.apple.com/membercenter/index.action">apple member center</a></p>
<p>2.点击进入Certificates, Identifiers &amp; Profiles</p>
<p><img alt="" src="./image/tuisong_1.jpg" /></p>
<p>3.点击进入iOS Apps下面的Provisioning Portal</p>
<p><img alt="" src="./image/tuisong_2.png" /></p>
<p>4.点击App IDs栏目中的加号，根据提示创建应用ID(图1)，如图2所示，在创建过程中勾选Push Notification服务；</p>
<p><strong>图1</strong></p>
<p><img alt="" src="./image/tuisong_3.png" /></p>
<p><img alt="" src="./image/tuisong_19.png" /></p>
<p><strong>图2</strong></p>
<p><img alt="" src="./image/tuisong_4.jpg" /></p>
<h3 id="_3">创建和上传证书<a class="headerlink" href="#_3" title="Permanent link">&para;</a></h3>
<p>1.创建完成后再次点击应用，点击Edit；</p>
<p><img alt="" src="./image/tuisong_6.jpg" /></p>
<p>2.点击创建证书（图1）,并根据提示创建证书（图2）， </p>
<p><strong>图1</strong></p>
<p><img alt="" src="./image/tuisong_7.jpg" /></p>
<p><strong>图2</strong></p>
<p><img alt="" src="./image/tuisong_8.jpg" /></p>
<p>3.生成证书后点击一下步，并上传刚刚创建好的证书，点击生成</p>
<p><img alt="" src="./image/tuisong_9.jpg" /></p>
<p>4.如图所示，点击Download下载APNs，完成后点击Done。</p>
<p><img alt="" src="./image/tuisong_10.jpg" /></p>
<p>5.导出.p12文件</p>
<ul>
<li>双击刚刚生成的.cer文件；</li>
</ul>
<p><img alt="" src="./image/tuisong_11.jpg" /></p>
<ul>
<li>进入"钥匙串访问"，选中刚刚导入的证书；</li>
</ul>
<p><img alt="" src="./image/tuisong_12.jpg" /></p>
<ul>
<li>选择导出项目（图1），导出.12文件，可以修改文件保存位置为桌面，方便后续上传（图2）；</li>
</ul>
<p><strong>图1</strong></p>
<p><img alt="" src="./image/tuisong_13.jpg" /></p>
<p><strong>图2</strong></p>
<p><img alt="" src="./image/tuisong_14.jpg" /></p>
<ul>
<li>点击存储，会提示设置密码，此处密码需为空，点击“好”，根据提示输入登录密码即可导出。</li>
</ul>
<p><img alt="" src="./image/tuisong_15.jpg" /></p>
<p>6.按照1~5步创建开发证书</p>
<p><img alt="" src="./image/tuisong_16.jpg" /></p>
<p>7.进入Bmob后台，在消息推送的推送设置处上传刚刚生成的两个.p12文件，并且选择目前是开发状态还是生产状态（图1）。<code>证书是具有有效时间的，需要注意在过期后重新生成</code></p>
<p><strong>图1</strong></p>
<p><img alt="" src="./image/tuisong_17.png" /></p>
<p><strong>图2</strong></p>
<p><img alt="" src="./image/tuisong_18.jpg" /></p>
<h2 id="_4">推送使用<a class="headerlink" href="#_4" title="Permanent link">&para;</a></h2>
<p>使用Bmob的推送服务，需要添加BmobSDK及其依赖库，具体可以参考<a href="http://docs.bmob.cn/data/iOS/a_faststart/doc/index.html">BmobSDK iOS快速入门</a></p>
<h3 id="_5">推送消息接收<a class="headerlink" href="#_5" title="Permanent link">&para;</a></h3>
<p>接收推送消息需要做两件事情，一是注册远程推送，一是将注册后得到的Token值保存至服务器。</p>
<p>1.注册远程推送，在AppDelegate.m中的<code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions</code>中使用以下代码</p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [Bmob registerWithAppKey:@&quot;your appkey&quot;];

    // Override point for customization after application launch.
    //注册推送，iOS 8的推送机制与iOS 7有所不同，这里需要分别设置
    if ([[[UIDevice currentDevice] systemVersion] floatValue] &gt;= 8.0) {
        UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc]init];
        //注意：此处的Bundle ID要与你申请证书时填写的一致。
        categorys.identifier=@&quot;com.bmob.bmobpushdemo&quot;;

        UIUserNotificationSettings *userNotifiSetting = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound) categories:[NSSet setWithObjects:categorys,nil]];

        [[UIApplication sharedApplication] registerUserNotificationSettings:userNotifiSetting];

        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }else {
        //注册远程推送
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
    }
    return YES;
}

</code></pre>

<p>2.在AppDelegate.m中添加以下代码，上传Token至服务器</p>
<pre><code>-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{

    //注册成功后上传Token至服务器
    BmobInstallation  *currentIntallation = [BmobInstallation installation];
    [currentIntallation setDeviceTokenFromData:deviceToken];
    [currentIntallation saveInBackground];
}
</code></pre>

<p>至此就可以接收到通知消息了。</p>
<p><code>注意</code></p>
<ol>
<li>
<p>iOS的推送只能在真机上使用，因此测试只能在真机上进行。</p>
</li>
<li>
<p>项目一般需要设置自己的 <code>Provisioning Profile</code> ，如果是第一次跑该应用程序，可能会遇到以下问题，这是没有设置 <code>Provisioning Profile</code> 导致的。</p>
</li>
</ol>
<pre><code>Domain=NSCocoaErrorDomain Code=3000 &quot;未找到应用程序的“aps-environment”的权利字符串&quot;
</code></pre>

<p>解决过程如下：
1）添加一个新的许可文件（如下图），将你要测试的设备添加入许可文件，并将该文件下载下来，双击安装至xcode;</p>
<p><img alt="" src="./image/tuisong_22.png" /></p>
<p>2）在Build Settings/Code Signing/Prvisioning Profile中选择刚刚导入至xcode的许可文件。</p>
<p><img alt="" src="./image/tuisong_20.jpg" /></p>
<p>3）在info.plist的Bundle identifier中填入Bundle ID即可，注意：此处的Bundle ID要与你申请证书时填写的一致。</p>
<p><img alt="" src="./image/tuisong_21.jpg" /></p>
<p>完成上述内容后，如果你的应用不是在运行状态，苹果的服务器就会发送推送至用户的设备上，并且由操作系统显示给用户，并不需要开发者做任何操作。如果推送到达时，应用是处于前台运行状态，开发者可以解析这条推送的内容。代码如下：</p>
<pre><code class="objc">- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    // 处理推送消息
    NSLog(@&quot;userinfo:%@&quot;,userInfo);
   
    NSLog(@&quot;收到推送消息:%@&quot;,[[userInfo objectForKey:@&quot;aps&quot;] objectForKey:@&quot;alert&quot;]);
｝
</code></pre>

<h3 id="_6">推送消息发送<a class="headerlink" href="#_6" title="Permanent link">&para;</a></h3>
<p>推送消息一种是直接在Web端进行发送，另外一种则是在app端进行发送。</p>
<h4 id="web">Web端发送<a class="headerlink" href="#web" title="Permanent link">&para;</a></h4>
<p>完成以上步骤后，你可以运行应用程序，从web推送一条消息给客户端。</p>
<p><img alt="" src="./image/pushmsg.png" /></p>
<p>在后台推送消息给Android和iOS两个平台的时候，有一些需要注意的：</p>
<p>1、由于Android和iOS的提送机制不同，iOS要经过APNS，Android的推送完全是走Bmob的长连接服务，为兼容这个问题，如果你选择发送格式为“json”格式时，需要添加APNS兼容头部（见下面json的aps部分），推送内容格式如下：</p>
<pre><code>{
    &quot;aps&quot;: {
    &quot;sound&quot;: &quot;cheering.caf&quot;, 
    &quot;alert&quot;: &quot;这个是通知栏上显示的内容&quot;, 
    &quot;badge&quot;: 0 
    }, 
    &quot;xx&quot; : &quot;json的key-value对，你可以根据情况添加更多的，客户端进行解析获取&quot;, 
}
</code></pre>

<p>其中，sound是iOS接收时的声音，badge是iOS通知栏的累计消息数(<code>目前该值服务器并没有主动处理，需要开发者自行维护该值</code>)。</p>
<p>2、如果你选择发送格式为“text”时，推送内容为“推送消息测试。。。。”，Bmob会自动添加aps部分发送给APNS，，相当于自动生成如下的json格式的推送内容：</p>
<pre><code>{
    &quot;aps&quot;: {
        &quot;alert&quot;: &quot;推送消息测试。。。。&quot;, 
    }
}
</code></pre>

<p>同时，也会发送给Android端，相当于自动生成如下的json格式的推送内容：</p>
<pre><code>{
    &quot;alert&quot; : &quot;推送消息测试。。。。&quot;, 
}
</code></pre>

<p>3、如果只是发送给Android端，大家可以自定义json格式的数据。</p>
<p>4、由于iOS的APNS的推送的大小是有限制的，默认最多256bytes，因此,如果你需要跨平台互通的话，需注意推送的内容不要太长。</p>
<p>5、想要更多了解Bmob的推送格式的朋友，如即时聊天，可以查看我们在问答社区中的回答：<a href="http://wenda.bmob.cn//?/question/204">http://wenda.bmob.cn//?/question/204</a></p>
<h4 id="app">app端发送<a class="headerlink" href="#app" title="Permanent link">&para;</a></h4>
<p>app端推送我们可以有以下类型</p>
<ol>
<li>广播推送，即给所有安装了该应用的设备发送推送</li>
<li>组播推送，即给特定用户群发送推送</li>
<li>点播推送，即给特定某一用户发送推送</li>
</ol>
<h5 id="_7">广播推送<a class="headerlink" href="#_7" title="Permanent link">&para;</a></h5>
<p>采用以下代码</p>
<pre><code>BmobPush *push = [BmobPush push];
//设置推送消息
[push setMessage:@&quot;所有人的推送的消息&quot;];
//发送推送
[push sendPushInBackgroundWithBlock:^(BOOL isSuccessful, NSError *error) {
        NSLog(@&quot;error %@&quot;,[error description]);
}];
</code></pre>

<h5 id="_8">组播推送<a class="headerlink" href="#_8" title="Permanent link">&para;</a></h5>
<p>可以自定义筛选条件给特定的用户群进行推送，这里我们将通过案例来说明如何使用组播推送。</p>
<h6 id="1">1.根据订阅频道推送<a class="headerlink" href="#1" title="Permanent link">&para;</a></h6>
<p>如我们做电台应用，只希望给订阅了特定频道的用户进行推送，我们可以使用利用在Intallation表中定义了的<code>channels</code>字段，我们可以设置该字段，然后只给订阅了特定channels的用户推送消息。首先，来看看如何设置该字段。</p>
<p><strong>覆盖已订阅的频道：</strong></p>
<pre><code>BmobInstallation  *currentIntallation = [BmobInstallation objectWithoutDatatWithClassName:nil objectId:@&quot;szK8444I&quot;];
[currentIntallation setObject:@[@&quot;Giants&quot;,@&quot;Mets&quot;] forKey:@&quot;channels&quot;];
[currentIntallation updateInBackground];
</code></pre>

<p><strong>订阅一个新频道，不覆盖已订阅的频道:</strong></p>
<pre><code>BmobInstallation  *currentIntallation = [BmobInstallation objectWithoutDatatWithClassName:nil objectId:@&quot;szK8444I&quot;];
[currentIntallation subscribeFromChannels:@[@&quot;Giants&quot;]];
[currentIntallation updateInBackground];
</code></pre>

<p><strong>退订一个订阅频道</strong></p>
<pre><code>BmobInstallation  *currentIntallation = [BmobInstallation objectWithoutDatatWithClassName:nil objectId:@&quot;szK8444I&quot;];
[currentIntallation unsubscribeFromChannels:@[@&quot;Giants&quot;]];
[currentIntallation updateInBackground];
</code></pre>

<p>设置好订阅频道后我们可以给订阅了特定频道的用户推送消息，代码如下：</p>
<pre><code>BmobPush *push = [BmobPush push];
[push setMessage:@&quot;推送给订阅了体育频道的用户&quot;];
[push setChannel:@&quot;Sports&quot;];
[push sendPushInBackgroundWithBlock:^(BOOL isSuccessful, NSError *error) {
        NSLog(@&quot;error %@&quot;,[error description]);
}];
</code></pre>

<h6 id="2">2.根据特定的查询条件进行推送<a class="headerlink" href="#2" title="Permanent link">&para;</a></h6>
<p>我们可以设置查询条件，然后给符合条件的用户进行推送，样例如下：</p>
<pre><code>BmobQuery *query = [BmobInstallation query];
//设置查询条件
...

BmobPush *push = [BmobPush push];
[push setQuery:query];
[push setMessage:@&quot;推送给满足条件的用户&quot;];
[push sendPushInBackgroundWithBlock:^(BOOL isSuccessful, NSError *error) {
    NSLog(@&quot;error %@&quot;,[error description]);
}];
</code></pre>

<p>如我们可以根据平台进行推送</p>
<p>1）推送给安卓用户</p>
<pre><code>BmobPush *push = [BmobPush push];
BmobQuery *query = [BmobInstallation query];
[query whereKey:@&quot;deviceType&quot; equalTo:@&quot;android&quot;];
[push setQuery:query];
[push setMessage:@&quot;推送给安卓用户的消息&quot;];
[push sendPushInBackgroundWithBlock:^(BOOL isSuccessful, NSError *error) {
    NSLog(@&quot;error %@&quot;,[error description]);
}];
</code></pre>

<p>2）推送给苹果用户</p>
<pre><code>BmobPush *push = [BmobPush push];
BmobQuery *query = [BmobInstallation query];
[query whereKey:@&quot;deviceType&quot; equalTo:@&quot;ios&quot;];
[push setQuery:query];
push setMessage:@&quot;推送给苹果用户的消息&quot;];
[push sendPushInBackgroundWithBlock:^(BOOL isSuccessful, NSError *error) {
        NSLog(@&quot;error %@&quot;,[error description]);
}];
</code></pre>

<h5 id="_9">点播推送<a class="headerlink" href="#_9" title="Permanent link">&para;</a></h5>
<p>给特定的用户发送信息，推送给安卓用户与推送给苹果用户有所区别，样例如下：</p>
<p>1、发送给单个安卓用户</p>
<pre><code>BmobPush *push = [BmobPush push];
BmobQuery *query = [BmobInstallation query];
[query whereKey:@&quot;installationId&quot; equalTo:@&quot;xxxxxxxxxxxxxxxx&quot;];
[push setQuery:query];
[push setMessage:@&quot;推送给某个安卓用户的消息&quot;]
[push sendPushInBackgroundWithBlock:^(BOOL isSuccessful, NSError *error) {
        NSLog(@&quot;error %@&quot;,[error description]);
}];
</code></pre>

<p>2、推送给单个苹果用户</p>
<pre><code>BmobPush *push = [BmobPush push];
BmobQuery *query = [BmobInstallation query];
[query whereKey:@&quot;deviceToken&quot; equalTo:@&quot;xxxxxxxxxxxxxxxx&quot;];
[push setQuery:query];
[push setMessage:@&quot;推送给某个苹果用户的消息&quot;]
[push sendPushInBackgroundWithBlock:^(BOOL isSuccessful, NSError *error) {
        NSLog(@&quot;error %@&quot;,[error description]);
}];
</code></pre>
                </div>
            </div>
        </div>

        
            <script>var base_url = '../..';</script>
            <script src="../../js/jquery-1.10.2.min.js"></script>
            <script src="../../js/bootstrap-3.0.3.min.js"></script>
            <script src="../../js/highlight.pack.js"></script>
            <script src="../../js/main.js"></script>
            <script src="../../js/base.js"></script>

        <div id="go-top"><i class="fa fa-chevron-up"></i></div>
        <a href="https://docs.bmob.cn/data/Android/a_faststart/doc/index.html" id="back" target="_blank">返回 <br> 旧版</a>
    </body>

</html>